package kiwi.assist.dev.guieditor.mediator {
	import kiwi.assist.dev.guieditor.model.UiDetailVO;

	import org.aswing.JOptionPane;

	import kiwi.assist.dev.guieditor.event.GUIEditorEvent;

	import org.robotlegs.mvcs.Mediator;

	import flash.events.Event;

	/**
	 * 菜单的媒介
	 * @author zhangming.luo
	 */
	public class GuiEditorMenuMediator extends Mediator {
		[Inject]
		public var detail : UiDetailVO;

		override public function onRegister() : void {
			super.onRegister();
			addViewListener(GUIEditorEvent.NEW_PROJECT, dispatch);
			addViewListener(GUIEditorEvent.LOAD_UIXML, dispatch);
			addViewListener(GUIEditorEvent.SAVE_UIXML, dispatch);
			addViewListener(GUIEditorEvent.PUBLISH_AS, dispatch);
			addViewListener(GUIEditorEvent.PUBLISH_JS, dispatch);
			addViewListener(GUIEditorEvent.SHOW_CONTAINER_SELECT_DIALOG, dispatch);
			addViewListener(GUIEditorEvent.BATCH_PUBLISH, handleBatchPublish);
		}

		private function handleBatchPublish(e : Event) : void {
			JOptionPane.showInputDialog("选择目录", "选择导出的目录", function(path : String) : void {
				dispatch(new GUIEditorEvent(GUIEditorEvent.BATCH_PUBLISH, path));
			}, detail.projectPath || "", null, true);
		}
	}
}
